package com.javaee.term.mapper;

import com.javaee.term.data.TurnOver;
import com.javaee.term.dto.ContactDto;
import com.javaee.term.model.Contact;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

public interface ContactMapper extends BaseMapper<Contact> {

    @Select("select * from contact limit #{currIndex} , #{pageSize}")
    List<Contact> selectBypage(Map<String, Object> data);
    @Select("select count(*) from contact")
    Integer selectAllCount();

    @Select(" select * from contact left join customer on contact.customer_id=customer.customer_id where contact.man_id= #{manId}")
    List<ContactDto> selectContactAndCustomer(Integer manId);
    /**
     * 统计每年
     */
    @Select("SELECT SUM(contact_money) y,YEAR(create_time) label from `contact` \n" +
            "GROUP BY YEAR(create_time)")
    List<TurnOver> selectTrunOverData();
    /**
     * 统计某年每个月
     * @param
     * @return
     */
    @Select("SELECT SUM(contact_money) y,MONTH(create_time) label from `contact` \n" +
            "where YEAR(create_time) = #{year} GROUP BY MONTH(create_time)")
    List<TurnOver> selectTheSumEachMouth(String year);
    /**
     * 按季统计
     * @param
     * @return
     */
    @Select("SELECT SUM(contact_money) y,QUARTER(create_time) label from `contact` \n" +
            "where YEAR(create_time) = #{year} GROUP BY QUARTER(create_time)")
    List<TurnOver> selectTheSumEachWeek(String year);
}
